//Ext.Loader.require("AmpleHarvest.Data.Model.cQueryCondition");

Ext.define("AmpleHarvest.DATA.Store.cQueryCondition", 
{
    extend: 'Ext.data.TreeStore',
	requires	:
		[
		 	'AmpleHarvest.DATA.Model.cQueryCondition'
		],
    model: 'AmpleHarvest.DATA.Model.cQueryCondition',
    indexOf: function(arg1) 
    {
    	return arg1.data.index;
    },
    proxy: 
    {
    	type: 'ajax',
    	url: obj_config.C_STR_EXTERNAL_PATH+'/enhancedSearch/read.php',
            reader: {
            	type: 'json'
            }
   	},
   	folderSort: false,
   	
   	get_QueryObject:function()
   	{
   		var arr_Query = this.tree.root.childNodes;

   		var obj_Query = new Object;
   		obj_Query.Query = new Array();
   		
   		for(var int_I=0;int_I < arr_Query.length;int_I++)
   		{
   			obj_Query.Query.push(this.process_Group2JSON(arr_Query[int_I]));
   		}
   		
   		return obj_Query;
   	},
   	
   	get_QueryAsJSON:function()
   	{
   		return Ext.JSON.encode(this.get_QueryObject());
   	},
   	
   	process_Group2JSON:function(obj_Group)
   	{
	   	var obj_Condition = new Object
   		
   		if(obj_Group.data.leaf)
   		{
   			obj_Condition.condition 	= obj_Group.data.condition;
   			obj_Condition.property 		= obj_Group.data.property;
   			//obj_Condition.prefix 		= +"*.";
   			obj_Condition.type			= "condition";
   			obj_Condition.value			= obj_Group.data.value;
   		}
   		else
		{
   			obj_Condition.children 		= new Array();
   			obj_Condition.type			= "group"
   			
   			for(var int_I=0;int_I < obj_Group.childNodes.length;int_I++)
   	   		{
   				obj_Condition.children.push(this.process_Group2JSON(obj_Group.childNodes[int_I]));
   	   		}
		}
		
   		obj_Condition.join			= obj_Group.data.bool;
	   	
	   	return obj_Condition;   		
   	}
});
